<?php
    include('./request.php');
    include('./config.php');
    $marketname = $result->marketname;
    $arr = array();
    try{
        $pdo = new PDO($dsn,$user,$pass);
        $sql = "select * from purchaseorder where market_name = '".$marketname."'";
        $res = $pdo->prepare($sql);
        $res->execute();
        while($rea=$res->fetch(PDO::FETCH_ASSOC)){
            $sql = "select * from user where user_id=".$rea['user_id'];
            $res2 = $pdo->prepare($sql);
            $res2->execute();
            $rea2 = $res2->fetch(PDO::FETCH_ASSOC);
            $username = $rea2['user_name'];
            $sql2 = "select goods_num from goodsmodel where goods_id=".$rea['goods_id']." and goods_model='".$rea['goods_model']."'";
            $res3=$pdo->prepare($sql2);
            $res3->execute();
            $rea3 = $res3->fetch(PDO::FETCH_ASSOC);
            $goodsnum = $rea3['goods_num'];
            if($rea['sendState']=="已发货"){
                $temp = array('username'=>$username,'goods_id'=>$rea['goods_id'],'goods_name'=>$rea['goods_name'],'goods_model'=>$rea['goods_model'],'goods_num'=>$goodsnum,'goods_type'=>$rea['goods_type'],'goods_date'=>$rea['order_date'],'sendState'=>$rea['sendState'],'accState'=>$rea['accState'],'address'=>$rea['adress'],'sendG'=>false);
                array_unshift($arr,$temp);
            }else{
            $temp = array('username'=>$username,'goods_id'=>$rea['goods_id'],'goods_name'=>$rea['goods_name'],'goods_model'=>$rea['goods_model'],'goods_num'=>$goodsnum,'goods_type'=>$rea['goods_type'],'goods_date'=>$rea['order_date'],'sendState'=>$rea['sendState'],'accState'=>$rea['accState'],'address'=>$rea['adress'],'sendG'=>true);
            array_unshift($arr,$temp);
         }
        }
        echo json_encode($arr);
    }catch(PDOException $e){
        echo "服务器开小差了";
    }
?>